import Paging from '../../../../wxjs/Paging.js'
import navToNext from '../../../../wxjs/navToNext.js'
var pag = new Paging();
const app = getApp();

var data = {
  xhx_images: app.xhx_images,
  xhx_route: app.xhx_route,
  userMatchOrder:null,
  navIndex:'1',
  navArray: [{ type: '1', name: '日' }, { type: '2', name: '周' }, { type: '3', name: '月' }, { type: '4', name: '其他' }],
  // navArray: [{ type: '1', name: '日' }, { type: '2', name: '周' }, { type: '3', name: '月' }, { type: '4', name: '自建' }],
};

var currentPage = {
  data,
  reqUrl: app.serAddrs.getUserMatchOrderList,
  onLoad,
  navTap,
  getList,
  getUserMatchOrderStatic,
};

var page = Object.assign({},navToNext, pag.func(), currentPage);

Page(page);

function onLoad(options) {
  const that = this;
  that.setData({
    navIndex: options && options.type || '4'
  })
  if (options.type <= 3) {
    this.listParams.customScheduleType = '';
    this.reqUrl = app.serAddrs.getUserMatchOrderList 
  } else {
    this.listParams.customScheduleType = 4;
    this.reqUrl = app.serAddrs.selfGetList
  }
  that.getList();
}

function getList(){
  const that = this;
  that.listParams.scheduleType = that.data.navIndex;
  that.pageListInit();
  that.getUserMatchOrderStatic();
}
// 我的打卡赛数据统计
function getUserMatchOrderStatic() {
  const that = this;
  var param={};
  param.scheduleType = that.data.navIndex;
  app.middleware.requestAjax({
    serAddr: app.serAddrs.getUserMatchOrderStatic,
    data: param,
    cancelToast: true,
    success: function (res) {
      that.setData({
        userMatchOrder: res.data
      })
    },
    fail: function (res) {
      app.middleware.showToast(res && res.msg || "加载失败");
    }
  })
}

function navTap(e){
  this.setData({
    navIndex: e.target.dataset.id
  });
  this.reqUrl = e.target.dataset.id <= 3 ? app.serAddrs.getUserMatchOrderList : app.serAddrs.selfGetList
  if(e.target.dataset.index <= 3) {
    this.listParams.customScheduleType = '';
  } else {
    this.listParams.customScheduleType = 4;
  }
  this.getList();
}
